# calculates frequency of occurance of All groups
# echoes latex- table code
# line 1 of table:
#  Testsatz
#  & \multicolumn{2}{c}{Inhalt1} 
#  & \multicolumn{2}{c}{Inhalt1}
#  & \multicolumn{2}{c}{Inhalt1} 
#  & \multicolumn{2}{c}{Inhalt1}
#  & \multicolumn{2}{c}{Inhalt1} 
#  & \multicolumn{2}{c}{Inhalt1} \\

getAllCSPGroupSummaries <- function(Pversion=0) {
  if('package:xtable' %in% search() || require('xtable',quietly=TRUE)) {}
  
  IXSUM <- getCSPGroupSummary("INDEX_MAJORS", Pversion=Pversion)
  DJISUM <- getCSPGroupSummary("DJI_STOCKS", Pversion=Pversion)
  SCSUM <- getCSPGroupSummary("SMALL_CAPS", Pversion=Pversion)
  PMSUM <- getCSPGroupSummary("METALS", Pversion=Pversion)
  AGSUM <- getCSPGroupSummary("AGRICULTURE", Pversion=Pversion)
  FXSUM <- getCSPGroupSummary("FOREX_MAJORS", Pversion=Pversion)
  mytable <- cbind(rbind (IXSUM$summary$matrix[,1:2], c(IXSUM$summary$sumobs,0)),
                   rbind (DJISUM$summary$matrix[,1:2], c(DJISUM$summary$sumobs,0)),
                   rbind (SCSUM$summary$matrix[,1:2], c(SCSUM$summary$sumobs,0)),
                   rbind (PMSUM$summary$matrix[,1:2], c(PMSUM$summary$sumobs,0)), 
                   rbind (AGSUM$summary$matrix[,1:2], c(AGSUM$summary$sumobs,0)), 
                   rbind (FXSUM$summary$matrix[,1:2], c(FXSUM$summary$sumobs,0)))
  filter=""
  if (Pversion==0) {
    filter="Donchian Channel Trendfilter"
  } else if (Pversion==2) {
    filter="GD Trendfilter"
  } else if (Pversion==22) {
    filter="GD Trendfilter. Bestätigung durch Lage der Folgekerze"
  } else if (Pversion==100) {
    filter="ohne Trendfilterung"    
  }
  title <- sprintf("Auftretensh\"aufigkeit der Kursmuster in verschiedenen M\"arkten mit %s ", filter)
  label <- "tab:CSPfrequency"
  xt <- xtable (mytable, 
                caption=title,
                label=label,
                align="|r|rc|rc|rc|rc|rc|rc|",
                display=c("s", "d","f", "d","f", "d","f", "d","f", "d","f", "d","f"))
  return(xt)
}